package com.yang.frost.blueberry.controller;

import com.yang.frost.blueberry.config.annotation.Log;
import com.yang.frost.blueberry.params.ArticleParam;
import com.yang.frost.blueberry.params.CmsArticlePageOrderParam;
import com.yang.frost.blueberry.params.DeleteParam;
import com.yang.frost.blueberry.service.CmsArticleService;
import com.yang.frost.blueberry.util.ApiResult;
import com.yang.frost.blueberry.util.Object2MapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 10296
 * @date 2021/3/10
 * @Description: 文章管理控制类
 */
@RestController
@RequestMapping("/cms/article")
@Api(value = "文章管理API", tags = {"文章管理"})
public class CmsArticleController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private CmsArticleService cmsArticleService;

    @Log("文章管理--列表查询")
    @PostMapping("/qryArticleList")
    @ApiOperation(value = "文章管理--文章列表查询", notes = "文章管理--分页查询文章列表")
    public ApiResult qryArticleList(@RequestBody CmsArticlePageOrderParam articleParam, HttpServletResponse response) {
        logger.info(articleParam + "");


        return cmsArticleService.qryArticleList(articleParam);
    }

    @Log("文章管理--新增文章")
    @PostMapping("/create")
    @ApiOperation(value = "文章管理--新增文章", notes = "文章管理--新增文章")
    public ApiResult create(@Validated @RequestBody ArticleParam articleParam, HttpServletResponse response) {


        return ApiResult.ok("返回成功");
    }

    @Log("文章管理--删除文章")
    @PostMapping("/delete")
    @ApiOperation(value = "文章管理--删除文章", notes = "文章管理--删除文章")
    public ApiResult delete(@Validated @RequestBody DeleteParam param, HttpServletResponse response) {

        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("articleId", param.getId());
        paramsMap.put("updateBy", param.getUserName() == null ? "" : param.getUserName());
        paramsMap.put("deleted", "1");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = dateFormat.format(new Date());
        paramsMap.put("remark", "删除操作【" + format + "】");


//        return cmsArticleService.deleteArticle(paramsMap);
        return ApiResult.ok(paramsMap);
    }

    @Log("文章管理--修改文章")
    @PostMapping("/update")
    @ApiOperation(value = "文章管理--修改文章", notes = "文章管理--修改文章")
    public ApiResult update(@Validated @RequestBody ArticleParam articleParam, HttpServletResponse response) {


        return ApiResult.ok("返回成功");
    }

    @Log("文章管理--查看文章详情")
    @PostMapping("/qryArticleDetails")
    @ApiOperation(value = "文章管理--查看文章详情", notes = "文章管理--查看文章详情")
    public ApiResult qryArticleDetails(@Validated @RequestBody ArticleParam articleParam, HttpServletResponse response) {


        return ApiResult.ok("返回成功");
    }


}
